package cn.airia.blog.util
{
	import flash.display.Sprite;
	import flash.geom.Rectangle;
	
	import flashx.textLayout.container.ContainerController;
	import flashx.textLayout.conversion.TextConverter;
	import flashx.textLayout.edit.SelectionManager;
	import flashx.textLayout.elements.TextFlow;
	
	import mx.core.UIComponent;
	import mx.managers.CursorManager;
	
	import spark.components.VGroup;

	public class TextLayoutUtil
	{
		public function TextLayoutUtil()
		{
		}
		private var _textContainer:Sprite;
		private var _textFlow:TextFlow;
		
		public function doReadOnlyTextLayout(textInput:XML,parentContainer:VGroup):void
		{
			_textContainer = new Sprite();
			var uicomp:UIComponent = new UIComponent();
			uicomp.addChild(_textContainer);
			parentContainer.addElement(uicomp);		
			_textFlow = TextConverter.importToFlow(textInput, TextConverter.TEXT_LAYOUT_FORMAT);
			var controller:ContainerController = new ContainerController(_textContainer, parentContainer.width-5, parentContainer.height);
			_textFlow.flowComposer.addController(controller);
			_textFlow.interactionManager = new SelectionManager();
			_textFlow.interactionManager.selectRange(0,0);			
			_textFlow.flowComposer.updateAllControllers();
			var bounds:Rectangle = controller.getContentBounds();
			if(bounds.height<=600)
			{
				parentContainer.height = bounds.height;
			}
		}
	}
}